home *** CD-ROM | disk | FTP | other *** search
- @echo off
- REM ***********************************************************
- REM *** EnviEdit.bat - Edit the environment with DOS editor ***
- REM *** ver.3 ***
- REM ***********************************************************
-
- SET | CEnviD %0.bat
- GOTO CENVI_EXIT
-
- // read all the environment variables to initially clear them
- fp = fopen("~ENVEDT~.BAT","wt");
- assert( fp );
- oldvcount = 0;
- while ( line = gets() ) {
- if ( line[0] && (Equal=strchr(line,'=')) ) {
- strcpy(OriginalLine,line);
- Equal[0] = 0;
- // skip any environment variable that is in lower-case, such
- // as the "windir" variable made by windows
- if ( !strcmp(strupr(strcpy(UpperEnv,line)),line) ) {
- oldvarlist[oldvcount++] = line;
- fprintf(fp,"%s\n",OriginalLine);
- }
- }
- }
- fclose(fp);
-
- // let the standard editor edit this file
- system(P_SWAP,"EDIT ~ENVEDT~.BAT");
-
- // read in the newly-edited file
- fp = fopen("~ENVEDT~.BAT","rt");
- newvcount = 0;
- while ( line = fgets(fp) ) {
- if ( line[0] && (Equal=strchr(line,'=')) ) {
- newvarlist[newvcount++] = line;
- }
- }
- fclose(fp);
-
- // add old lines to remove old variables
- fp = fopen("~ENVEDT~.BAT","wt");
- fprintf(fp,"@echo off\n");
- for ( i = 0; i < oldvcount; i++ )
- fprintf(fp,"SET %s=\n",oldvarlist[i]);
- // add lines to set new variables
- for ( i = 0; i < newvcount; i++ )
- fprintf(fp,"SET %s",newvarlist[i]);
- fclose(fp);
-
- :CENVI_EXIT
- CALL ~ENVEDT~.BAT
- DEL ~ENVEDT~.BAT
-